package dao

import (
	"hong/uniapp_server/domain/user"
	"time"
)

type UserPhotoDao struct {}

func NewUserPhotoDao() *UserPhotoDao {
	return &UserPhotoDao{}
}

func (d *UserPhotoDao) Insert(photo *user.UserPhotoEntity) error {
	sql := "INSERT INTO user_photo (user_id, file_name, photo_size, created_at) VALUES (?, ?, ?, ?)"
	r, err := db.Exec(sql, photo.UserID, photo.FileName, photo.PhotoSize, time.Now())
	if err != nil {
		return err
	}
	id, err := r.LastInsertId()
	if err != nil {
		return err
	}
	photo.ID = id
	return nil
}
